package cn.wokoba.config;

import com.alibaba.nacos.api.config.ConfigService;
import com.alibaba.nacos.api.config.listener.Listener;
import com.alibaba.nacos.api.exception.NacosException;

public class NacosService {
    private final ConfigService configService;
    private final String dataId;
    private final String group;

    public NacosService(ConfigService configService, String dataId, String group) {
        this.configService = configService;
        this.dataId = dataId;
        this.group = group;
    }

    public String getConfig(long timeoutMs) throws NacosException {
        return configService.getConfig(dataId, group, timeoutMs);
    }

    public void addListener(Listener listener) throws NacosException {
        configService.addListener(dataId, group, listener);
    }

    public void removeListener(Listener listener) {
        configService.removeListener(dataId, group, listener);
    }

    public boolean publishConfig(String content) throws NacosException {
        return configService.publishConfig(dataId, group, content);
    }

}
